#include "aso_middle_layer.h"
#include "inc/gui_params.h"
#include <QByteArray>
#include <QDebug>

void runAso(QString sequence, QString database, PluginAdmin PA, int rank, QString comments, QString outFile)
{
    AntiviralSet antivirals;
    biopp::PseudoNucSequence nucSequence;
    outFile += ".trp";
    QString outDir = "../outputs/";
    outDir += outFile;
    load_sequence(qtTostdString(sequence), nucSequence);
    DataBase dataBase(qtTostdString(database));
    dataBase.get_antivirals(antivirals);
    AVIterator avIterator(antivirals.antivirals);
    AntiviralsNames rejected;

    if (PA.check_plugin(avIterator, rejected))
    {
        TherapyRanker rankerObserver(rank);
        TherapyGenImpl therapyGenerator(rankerObserver.get_observer(), antivirals, &PA);
        therapyGenerator.generateTherapies(nucSequence);
        qDebug() << outFile;
        gui_print_ranking(rankerObserver, qtTostdString(outDir), comments.toStdString());
    }
    else
    {
        qDebug() << "error";
    }
    PA.unload_plugin();

}

QString stdToqtString(const std::string& string)
{
    return QString::fromStdString(string);
}

const char* qtTostdString(QString string)
{
    QByteArray result = string.toAscii();
    return result.constData();
}
